import middleman_pb2
import uuid

class Game(object):
	def __init__(self, game_id, name, max_player_count):
		self.game = middleman_pb2.Game()
		self.game.game_id = game_id;
		self.game.game_name = name
		self.game.max_player_count = max_player_count

	def __str__(self):
		return self.game.game_name + "[" + str(self.game.max_player_count) + "]"


class NewGameRequest(object):
	def __init__(self, name, max_player_count):
		self.request = middleman_pb2.NewGameRequest()
		self.request.header.message_id = str(uuid.uuid4())
		self.request.header.message_type = "NewGameRequest"
		self.request.game_name = name
		self.request.max_player_count = max_player_count

	def __str__(self):
		return str(self.request)

	def get_game_name(self):
		return self.request.game_name

	def get_max_player_count(self):
		return self.request.max_player_count
		
	def serialize(self):
		return self.request.SerializeToString()

	def deserialize(self, message):
		self.request = middleman_pb2.NewGameRequest()
		self.request.ParseFromString(message)


class GameCreatedResponse(object):
	def __init__(self, game):
		self.response = middleman_pb2.GameCreatedResponse()
		self.response.header.message_id = str(uuid.uuid4())
		self.response.header.message_type = "GameCreatedResponse"
		self.response.game.game_id = game.game.game_id
		self.response.game.game_name = game.game.game_name
		self.response.game.max_player_count = game.game.max_player_count

	def __str__(self): 
		return str(self.response)

	def serialize(self):
		return self.response.SerializeToString()

	def deserialize(self, message):
		self.response = middleman_pb2.GameCreatedResponse()
		self.response.ParseFromString(message)

class Grid(object):
	def __init__(self):
		self.grid = middleman_pb2.Grid()

	def __str__(self):
		return str(self.grid)

	def serialize(self):
		return self.grid.SerializeToString()

	def deserialize(self, message):
		self.grid = middleman_pb2.Grid()
		self.grid.ParseFromString(message)		
